package com.villaday.idf.custom.pop;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import androidx.annotation.RequiresApi;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.Animation;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.google.gson.Gson;
import com.villaday.idf.R;
import com.villaday.idf.custom.LoadingDialog;
import com.villaday.idf.model3.HashPrice;
import com.villaday.idf.model3.HashPricesEntity;
import com.villaday.idf.model3.HashStatesEntity;
import com.villaday.idf.model3.StatesPostEntity;
import com.villaday.idf.util.Constant;
import com.villaday.idf.util.DateUtils;
import com.villaday.idf.util.LogUtil;
import com.villaday.idf.util.OkHttpUtil;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.PopularUtil;
import com.villaday.idf.util.SharedPreferencesUtil;
import com.villaday.idf.util.ToastUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import razerdp.basepopup.BasePopupWindow;

public class DataPop extends BasePopupWindow implements View.OnClickListener {

    private Context mContext;

    private boolean isNormal = true;
    private String title;
    private String type;
    private String mHouseId;
    private EditText mEtValue1;
    private EditText mEtValue2;
    private EditText mEtValue3;
    private EditText mEtValue4;
    private EditText mEtValue5;
    private EditText mEtValue6;
    private EditText mEtValue7;
    private TextView mTvDateStart;
    private TextView mTvDateEnd;
    private LoadingDialog mLoadDialog;
    private Activity mActivity;
    private boolean isStart = true;
    public OnBtnClickListener onBtnClickListener;
    //    private HashPricesEntity.BodyBean.DatesBean mDatesBean;
    private Calendar selectedDate = Calendar.getInstance();
    private String timeValue = "";
    private TextView mTvDateTime;
    private List<String> dates = new ArrayList<>();
    private TextView mTvConfirm;
    private LinearLayout llNorify;
    private TextView tvDataTitle1;
    private TextView tvTitle;
    private HashPricesEntity.BodyBean.DatesBeanX datesBeanX = new HashPricesEntity.BodyBean.DatesBeanX();


    /**
     * @param context
     * @param activity
     * @param mHouseId
     * @param name
     * @param type     结算模式
     * @param title    是否为通用
     * @param date
     */
    public DataPop(Context context, Activity activity, String mHouseId, String name, String type, String title, final String date) {
        super(context);
        mContext = context;
        mActivity = activity;
        setBackground(0);
        setOutSideDismiss(true);
        setKeepSize(true);
        setPopupFadeEnable(false);
        setBackgroundColor(Color.parseColor("#B3000000"));
        setBlurBackgroundEnable(true);
//        findViewById(R.id.ll_data).startAnimation(PopularUtil.buildAnimal());
        this.title = title;
        this.type = type;
        this.mHouseId = mHouseId;

        tvTitle = findViewById(R.id.tv_data_title);
        ImageView ivClose = findViewById(R.id.iv_data_close);
        mTvConfirm = findViewById(R.id.tv_d_confirm);
        llNorify = findViewById(R.id.ll_data_notify);


        mTvDateStart = findViewById(R.id.tv_date_start);
        mTvDateEnd = findViewById(R.id.tv_date_end);

        mTvDateTime = findViewById(R.id.tv_data_time);
        LinearLayout llDateStart = findViewById(R.id.ll_data_start);
        LinearLayout llDateEnd = findViewById(R.id.ll_data_end);

        tvDataTitle1 = findViewById(R.id.tv_data_title1);
        mEtValue1 = findViewById(R.id.et_data_value1);
        mEtValue2 = findViewById(R.id.et_data_value2);
        mEtValue3 = findViewById(R.id.et_data_value3);
        mEtValue4 = findViewById(R.id.et_data_value4);
        mEtValue5 = findViewById(R.id.et_data_value5);
        mEtValue6 = findViewById(R.id.et_data_value6);
        mEtValue7 = findViewById(R.id.et_data_value7);
        NestedScrollView nsv = findViewById(R.id.nsv_data);
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) nsv.getLayoutParams();
        setTextChange();


        switch (title) {
            case "通用":
                isNormal = true;
                tvTitle.setText("设置通用星期价格");
                HashPricesEntity.BodyBean bodyBean = new Gson().fromJson(date, HashPricesEntity.BodyBean.class);
                HashPricesEntity.BodyBean.WeekBean week = bodyBean.getWeek();
                if (week.getStartDate() != null && week.getEndDate() != null
                        && !TextUtils.isEmpty(week.getStartDate()) && !TextUtils.isEmpty(week.getEndDate())) {
                    mTvDateStart.setText(week.getStartDate());
                    mTvDateEnd.setText(week.getEndDate());
                } else {
                    mTvDateStart.setText(DateUtils.long2Data(System.currentTimeMillis()));
                    mTvDateEnd.setText(DateUtils.getdate(selectedDate.getActualMaximum(selectedDate.DAY_OF_MONTH)));
                }

                mEtValue1.setText(week.getMondayPrice().equals("/") ? "" : week.getMondayPrice());
                mEtValue2.setText(week.getTuesdayPrice().equals("/") ? "" : week.getTuesdayPrice());
                mEtValue3.setText(week.getWednesdayPrice().equals("/") ? "" : week.getWednesdayPrice());
                mEtValue4.setText(week.getThursdayPrice().equals("/") ? "" : week.getThursdayPrice());
                mEtValue5.setText(week.getFridayPrice().equals("/") ? "" : week.getFridayPrice());
                mEtValue6.setText(week.getSaturdayPrice().equals("/") ? "" : week.getSaturdayPrice());
                mEtValue7.setText(week.getSundayPrice().equals("/") ? "" : week.getSundayPrice());
                break;
            case "特殊":
                lp.width = MATCH_PARENT;//设置控件的宽
                lp.height = (int) PhoneUtil.dp2px(mContext, 220);//设置空间的高
                nsv.setLayoutParams(lp);
                tvTitle.setText("设置特殊日期价格");
                llNorify.setVisibility(View.VISIBLE);
                initOtherData();
                HashStatesEntity.BodyBean monthBean = new Gson().fromJson(date, HashStatesEntity.BodyBean.class);
                List<HashStatesEntity.BodyBean.MonthsBean> mMonths = monthBean.getMonths();
                List<HashStatesEntity.BodyBean.MonthsBean.DaysBean> list = new ArrayList<>();
                for (int i = 0; i < mMonths.size(); i++) {
                    for (int j = 0; j < mMonths.get(i).getDays().size(); j++) {
                        if (!mMonths.get(i).getDays().get(j).getText().equals("default")) {
                            list.add(mMonths.get(i).getDays().get(j));
                            if (mMonths.get(i).getDays().get(j).isSelect()) {
                                dates.add(mMonths.get(i).getDays().get(j).getDate());
                            }
                        }
                    }
                }

                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).isSelect()) {
                        if (i + 2 < list.size() && list.get(i + 1).isSelect() && list.get(i + 2).isSelect()) {
                            String startData = list.get(i).getDate();
                            String endDate = null;
                            boolean isOk = true;
                            for (int j1 = i; j1 < list.size(); j1++) {
                                if (isOk) {
                                    if (!list.get(j1).isSelect()) {
                                        i = j1 - 1;
                                        endDate = list.get(i).getDate();
                                        isOk = false;
                                    }

                                    if ((j1 == list.size() - 1 && list.get(j1).isSelect())) {
                                        i = j1;
                                        endDate = list.get(i).getDate();
                                        isOk = false;
                                    }
                                }
                            }
                            timeValue = timeValue + DateUtils.data2Data(startData) + "—" + DateUtils.data2Data(endDate) + "、";
                        } else {
                            timeValue = timeValue + DateUtils.data2Data(list.get(i).getDate()) + "、";
                        }
                    }
                }
                mTvDateTime.setText(timeValue.substring(0, timeValue.length() - 1));
                break;
            case "特殊修改":
                lp.width = MATCH_PARENT;//设置控件的宽
                lp.height = (int) PhoneUtil.dp2px(mContext, 220);//设置空间的高
                nsv.setLayoutParams(lp);
                tvTitle.setText("修改特殊日期价格");
                initOtherData();
                llNorify.setVisibility(View.VISIBLE);



                datesBeanX = new Gson().fromJson(date, HashPricesEntity.BodyBean.DatesBeanX.class);
                String titleOther = "";
                for (int i = 0; i < datesBeanX.getDates().size(); i++) {
                    HashPricesEntity.BodyBean.DatesBeanX.DatesBean datesBean = datesBeanX.getDates().get(i);
                    if (datesBean.getStartDate().equals(datesBean.getEndDate())) {
                        titleOther = titleOther + DateUtils.data2Data(datesBean.getStartDate()) + "、";
                    } else {
                        titleOther = titleOther + DateUtils.data2Data(datesBean.getStartDate()) + "-" + DateUtils.data2Data(datesBean.getEndDate()) + "、";
                    }

                }
                mTvDateTime.setText(titleOther.substring(0, titleOther.length() - 1));
                mEtValue1.setText(datesBeanX.getCostPrice());
                break;
        }

        llDateStart.setOnClickListener(this);
        llDateEnd.setOnClickListener(this);
        ivClose.setOnClickListener(this);
        mTvConfirm.setOnClickListener(this);
//        initRecycle();

    }


    public void initOtherData() {
        isNormal = false;
        tvDataTitle1.setText("价格");
        mEtValue1.setText("");
        mTvConfirm.setEnabled(false);
        mTvConfirm.setBackgroundResource(R.drawable.shape_gradient_7f_8e_40);
        findViewById(R.id.ll_data_start).setVisibility(View.VISIBLE);
        findViewById(R.id.tv_data_time).setVisibility(View.VISIBLE);
        findViewById(R.id.ll_data_start).setVisibility(View.GONE);
        findViewById(R.id.ll_data_end).setVisibility(View.GONE);
        findViewById(R.id.ll_data2).setVisibility(View.GONE);
        findViewById(R.id.ll_data3).setVisibility(View.GONE);
        findViewById(R.id.ll_data4).setVisibility(View.GONE);
        findViewById(R.id.ll_data5).setVisibility(View.GONE);
        findViewById(R.id.ll_data6).setVisibility(View.GONE);
        findViewById(R.id.ll_data7).setVisibility(View.GONE);


        mEtValue1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.toString().length() > 0) {
                    mTvConfirm.setEnabled(true);
                    mTvConfirm.setBackgroundResource(R.drawable.shape_fe_ff40);
                } else {
                    mTvConfirm.setEnabled(false);
                    mTvConfirm.setBackgroundResource(R.drawable.shape_gradient_7f_8e_40);
                }
            }
        });
    }


    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.popular_data);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_data_close:
                dismiss();
                break;
            case R.id.ll_data_start:
                isStart = true;
                initStartTime();
                break;
            case R.id.ll_data_end:
                isStart = false;
                initStartTime();
                break;
            case R.id.tv_d_confirm:
                if (isNormal) {
                    showDialog();
                    Map<String, Object> map = new HashMap<>();
                    HashPrice hashPrice = new HashPrice();
                    hashPrice.setMode(1);
                    hashPrice.setStartDate(mTvDateStart.getText().toString());
                    hashPrice.setEndDate(mTvDateEnd.getText().toString());
                    hashPrice.setMondayPrice(mEtValue1.getText().toString());
                    hashPrice.setTuesdayPrice(mEtValue2.getText().toString());
                    hashPrice.setWednesdayPrice(mEtValue3.getText().toString());
                    hashPrice.setThursdayPrice(mEtValue4.getText().toString());
                    hashPrice.setFridayPrice(mEtValue5.getText().toString());
                    hashPrice.setSaturdayPrice(mEtValue6.getText().toString());
                    hashPrice.setSundayPrice(mEtValue7.getText().toString());
                    LogUtil.jLog().e(new Gson().toJson(hashPrice));
                    OkHttpUtil.postJson(mContext, String.format(Constant.URL.hashPrices, SharedPreferencesUtil.getRoleInfoId(mContext), mHouseId), hashPrice, map, new OkHttpUtil.OnDataListener() {
                        @Override
                        public void onResponse(String url, String json) {
                            try {
                                LogUtil.jLog().e(json);
                                dismissDialog();
                                StatesPostEntity statesPostEntity = new Gson().fromJson(json, StatesPostEntity.class);
                                if (statesPostEntity.getCode().equals(Constant.Strings.SUC)) {
                                    onBtnClickListener.onBtnClick("保存成功");
                                    ToastUtil.initToast(mContext, "保存成功");
                                    dismiss();
                                } else {
                                    ToastUtil.initToast(mContext, statesPostEntity.getMsg());
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void onFailure(String url, String error) {

                        }
                    });
                } else {
                    showDialog();
                    Map<String, Object> map = new HashMap<>();
                    HashPrice hashPrice = new HashPrice();
                    hashPrice.setMode(2);
//                    hashPrice.setStartDate(mTvDateStart.getText().toString());
//                    hashPrice.setEndDate(mTvDateEnd.getText().toString());
                    hashPrice.setCostPrice(mEtValue1.getText().toString());

                    if (title.equals("特殊修改") && datesBeanX != null) {
                        hashPrice.setId(datesBeanX.getId());
                    } else if (title.equals("特殊")) {
                        hashPrice.setDates(dates);
                    }

                    LogUtil.jLog().e(new Gson().toJson(hashPrice));
                    OkHttpUtil.postJson(mContext, String.format(Constant.URL.hashPrices, SharedPreferencesUtil.getRoleInfoId(mContext), mHouseId), hashPrice, map, new OkHttpUtil.OnDataListener() {
                        @Override
                        public void onResponse(String url, String json) {
                            try {
                                LogUtil.jLog().e(json);
                                dismissDialog();
                                StatesPostEntity statesPostEntity = new Gson().fromJson(json, StatesPostEntity.class);
                                if (statesPostEntity.getCode().equals(Constant.Strings.SUC) && statesPostEntity.isBody()) {
                                    ToastUtil.initToast(mContext, "保存成功");
                                    dismiss();
                                    onBtnClickListener.onBtnClick("保存成功");
                                } else {
                                    ToastUtil.initToast(mContext, statesPostEntity.getMsg());
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void onFailure(String url, String error) {

                        }
                    });
                }
                break;


        }
    }


    public void setOnBtnClickListener(OnBtnClickListener onBtnClickListener) {
        this.onBtnClickListener = onBtnClickListener;
    }

    public interface OnBtnClickListener {
        void onBtnClick(String title);
    }


    private void initStartTime() {

//        String[] varStart = mTvDateStart.getText().toString().split("-");
        Calendar selectedDate = Calendar.getInstance();
        String[] varStart = DateUtils.long2Data(System.currentTimeMillis()).split("-");
        selectedDate.set(Integer.parseInt(varStart[0]), Integer.parseInt(varStart[1]) - 1, Integer.parseInt(varStart[2]));


        Calendar endDate = Calendar.getInstance();
        if (DateUtils.string2Data(mTvDateStart.getText().toString()) > System.currentTimeMillis()) {
            String[] varEnd = mTvDateStart.getText().toString().replace("/", "").split("-");
            endDate.set(Integer.parseInt(varEnd[0]), Integer.parseInt(varEnd[1]) - 1, Integer.parseInt(varEnd[2]));
        } else {
            String[] varEnd = DateUtils.long2Data(System.currentTimeMillis()).split("-");
            endDate.set(Integer.parseInt(varEnd[0]), Integer.parseInt(varEnd[1]) - 1, Integer.parseInt(varEnd[2]));
        }


        //正确设置方式 原因：注意事项有说明


        //正确设置方式 原因：注意事项有说明
        TimePickerView pvTime = new TimePickerBuilder(mContext, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
                if (isStart) {
                    mTvDateStart.setText(format.format(date));
                } else {
                    mTvDateEnd.setText(format.format(date));
                }
            }
        })
//                .setLayoutRes(R.layout.pickerview_time, new CustomListener() {
//            @Override
//            public void customLayout(View v) {
//                RelativeLayout rvTopbar = v.findViewById(R.id.rv_topbar);
//                Button btnCancel = v.findViewById(R.id.btnCancel);
//                TextView tvTitle = v.findViewById(R.id.tvTitle);
//                Button btnSubmit = v.findViewById(R.id.btnSubmit);
//
//                rvTopbar.setPadding(10, 10, 10, 10);
//                btnCancel.setTextColor(mContext.getResources().getColor(R.color.colorF73637));
//
//                btnSubmit.setBackgroundResource(R.drawable.shape_solid_73637_20);
//                btnSubmit.setGravity(Gravity.CENTER);
//                btnSubmit.setPadding(0,0,0,0);
//                btnSubmit.setTextColor(mContext.getResources().getColor(R.color.colorWhite));
//            }
//        })
                .setType(new boolean[]{true, true, true, false, false, false})// 默认全部显示
                .setCancelText("取消")//取消按钮文字
                .setSubmitText("确定")//确认按钮文字
                .setContentTextSize(15) //滚轮文字大小
                .setTitleSize(15)//标题文字大小
                .setTitleText(isStart ? "请选择开始时间" : "请选择结束时间")//标题文字
                .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
                .isCyclic(false)//是否循环滚动
                .setTitleColor(mContext.getResources().getColor(R.color.colorRed))//标题文字颜色
                .setSubmitColor(mContext.getResources().getColor(R.color.colorRed))//确定按钮文字颜色
                .setCancelColor(mContext.getResources().getColor(R.color.colorRed))//取消按钮文字颜色
                .setTitleBgColor(mContext.getResources().getColor(R.color.colorGrayBg))//标题背景颜色 Night mode
                .setBgColor(mContext.getResources().getColor(R.color.colorWhite))//滚轮背景颜色 Night mode
                .setDate(isStart ? selectedDate : endDate)// 如果不设置的话，默认是系统时间*/
                .setRangDate(isStart ? selectedDate : endDate, null)//起始终止年月日设定
                .setLabel("年", "月", "日", "时", "分", "秒")//默认设置为年月日时分秒
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .isDialog(true)//是否显示为对话框样式
                .build();


//        pvTime.setOnDismissListener(new com.bigkoo.pickerview.listener.OnDismissListener() {
//            @Override
//            public void onDismiss(Object o) {
////                showPopupWindow();
//            }
//        });
        Dialog mDialog = pvTime.getDialog();
        if (mDialog != null) {
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.BOTTOM);

            params.leftMargin = 0;
            params.rightMargin = 0;
            pvTime.getDialogContainerLayout().setLayoutParams(params);

            Window dialogWindow = mDialog.getWindow();
            if (dialogWindow != null) {
                dialogWindow.setWindowAnimations(com.bigkoo.pickerview.R.style.picker_view_slide_anim);//修改动画样式
                dialogWindow.setGravity(Gravity.BOTTOM);//改成Bottom,底部显示
            }
        }
        pvTime.show();
    }


    /**
     * 设置加载框
     */
    protected void showDialog() {
        if (mLoadDialog == null) {
            mLoadDialog = LoadingDialog.newInstance("加载中");
        }

        mLoadDialog.show(mActivity.getFragmentManager(), "loading");
    }


    /**
     * 设置加载框
     */
    protected void dismissDialog() {
        if (mLoadDialog != null) {
            mLoadDialog.dismiss();
        }
    }


    private void setTextChange() {


        mEtValue1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.toString().contains(".") && s.toString().split("\\.").length > 1
                        && s.toString().split("\\.")[1].length() > 2) {
                    mEtValue1.setText(s.toString().split("\\.")[0] + "." + s.toString().split("\\.")[1].substring(0, 2));
                    mEtValue1.setSelection(mEtValue1.length());
                }

                if (s.toString().equals(".")) {
                    mEtValue1.setText("0.");
                    mEtValue1.setSelection(mEtValue1.length());
                }

                if (s.length() > 1 && !s.toString().contains(".") && s.toString().substring(0, 1).equals("0")) {
                    mEtValue1.setText(s.toString().substring(1));
                    mEtValue1.setSelection(mEtValue1.length());
                }
            }
        });

        mEtValue2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
//                LogUtil.jLog().e(s.toString().split("\\.").length);
//                LogUtil.jLog().e(s.toString().split("\\.")[1]);
//                LogUtil.jLog().e(s.toString().split("\\.")[1].length());
                if (s.toString().contains(".") && s.toString().split("\\.").length > 1
                        && s.toString().split("\\.")[1].length() > 2) {
                    mEtValue2.setText(s.toString().split("\\.")[0] + "." + s.toString().split("\\.")[1].substring(0, 2));
                    mEtValue2.setSelection(mEtValue2.length());
                }


                if (s.toString().equals(".")) {
                    mEtValue2.setText("0.");
                    mEtValue2.setSelection(mEtValue2.length());
                }

                if (s.length() > 1 && !s.toString().contains(".") && s.toString().substring(0, 1).equals("0")) {
                    mEtValue2.setText(s.toString().substring(1));
                    mEtValue2.setSelection(mEtValue2.length());
                }
            }
        });

        mEtValue3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.toString().contains(".") && s.toString().split("\\.").length > 1
                        && s.toString().split("\\.")[1].length() > 2) {
                    mEtValue3.setText(s.toString().split("\\.")[0] + "." + s.toString().split("\\.")[1].substring(0, 2));
                    mEtValue3.setSelection(mEtValue3.length());
                }


                if (s.toString().equals(".")) {
                    mEtValue3.setText("0.");
                    mEtValue3.setSelection(mEtValue3.length());
                }

                if (s.length() > 1 && !s.toString().contains(".") && s.toString().substring(0, 1).equals("0")) {
                    mEtValue3.setText(s.toString().substring(1));
                    mEtValue3.setSelection(mEtValue3.length());
                }

            }
        });

        mEtValue4.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.toString().contains(".") && s.toString().split("\\.").length > 1
                        && s.toString().split("\\.")[1].length() > 2) {
                    mEtValue4.setText(s.toString().split("\\.")[0] + "." + s.toString().split("\\.")[1].substring(0, 2));
                    mEtValue4.setSelection(mEtValue4.length());
                }


                if (s.toString().equals(".")) {
                    mEtValue4.setText("0.");
                    mEtValue4.setSelection(mEtValue4.length());
                }

                if (s.length() > 1 && !s.toString().contains(".") && s.toString().substring(0, 1).equals("0")) {
                    mEtValue4.setText(s.toString().substring(1));
                    mEtValue4.setSelection(mEtValue4.length());
                }

            }
        });

        mEtValue5.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
//                LogUtil.jLog().e(s.toString().split("\\.").length);
//                LogUtil.jLog().e(s.toString().split("\\.")[1]);
//                LogUtil.jLog().e(s.toString().split("\\.")[1].length());
                if (s.toString().contains(".") && s.toString().split("\\.").length > 1
                        && s.toString().split("\\.")[1].length() > 2) {
                    mEtValue5.setText(s.toString().split("\\.")[0] + "." + s.toString().split("\\.")[1].substring(0, 2));
                    mEtValue5.setSelection(mEtValue5.length());
                }


                if (s.toString().equals(".")) {
                    mEtValue5.setText("0.");
                    mEtValue5.setSelection(mEtValue5.length());
                }

                if (s.length() > 1 && !s.toString().contains(".") && s.toString().substring(0, 1).equals("0")) {
                    mEtValue5.setText(s.toString().substring(1));
                    mEtValue5.setSelection(mEtValue5.length());
                }
            }
        });

        mEtValue6.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
//                LogUtil.jLog().e(s.toString().split("\\.").length);
//                LogUtil.jLog().e(s.toString().split("\\.")[1]);
//                LogUtil.jLog().e(s.toString().split("\\.")[1].length());
                if (s.toString().contains(".") && s.toString().split("\\.").length > 1
                        && s.toString().split("\\.")[1].length() > 2) {
                    mEtValue6.setText(s.toString().split("\\.")[0] + "." + s.toString().split("\\.")[1].substring(0, 2));
                    mEtValue6.setSelection(mEtValue6.length());
                }


                if (s.toString().equals(".")) {
                    mEtValue6.setText("0.");
                    mEtValue6.setSelection(mEtValue6.length());
                }

                if (s.length() > 1 && !s.toString().contains(".") && s.toString().substring(0, 1).equals("0")) {
                    mEtValue6.setText(s.toString().substring(1));
                    mEtValue6.setSelection(mEtValue6.length());
                }
            }
        });

        mEtValue7.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
//                LogUtil.jLog().e(s.toString().split("\\.").length);
//                LogUtil.jLog().e(s.toString().split("\\.")[1]);
//                LogUtil.jLog().e(s.toString().split("\\.")[1].length());
                if (s.toString().contains(".") && s.toString().split("\\.").length > 1
                        && s.toString().split("\\.")[1].length() > 2) {
                    mEtValue7.setText(s.toString().split("\\.")[0] + "." + s.toString().split("\\.")[1].substring(0, 2));
                    mEtValue7.setSelection(mEtValue7.length());
                }

                if (s.toString().equals(".")) {
                    mEtValue7.setText("0.");
                    mEtValue7.setSelection(mEtValue7.length());
                }

                if (s.length() > 1 && !s.toString().contains(".") && s.toString().substring(0, 1).equals("0")) {
                    mEtValue7.setText(s.toString().substring(1));
                    mEtValue7.setSelection(mEtValue7.length());
                }
            }
        });

    }

    @Override
    protected Animation onCreateShowAnimation() {
        return PopularUtil.ShowAnimation();
    }

    @Override
    protected Animation onCreateDismissAnimation() {
        return PopularUtil.dismissAnimation();
    }
}
